/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#ifndef __sgl_exceptions_h__
#define __sgl_exceptions_h__

#include <sgl/global_settings.h>
#include <stdexcept>

namespace sgl {

/******************************************************************************/
/*                                                                            */
/* precondition_violated                                                      */
/*                                                                            */
/******************************************************************************/

/// Exception class for precondition violations.
//!
//! In SGL, a precondition is a condition or predicate that must always be true 
//!	prior to the execution of some section of code. If a precondition is 
//! violated, the effect of the section of code becomes undefined and thus may 
//! or may not work as intended.
//! 
//! SGL checks preconditions with the SGL_PRECONDITION macro, which - when 
//! defined - throws the precondition_violated exception when the precondition 
//! is not true.
//!
//! The user of SGL can inhibit this behavior by defining the 
//! SGL_PRECONDITION(condition, message) macro as an empty macro before the 
//! inclusion of any SGL header file. 
class precondition_violated : public std::logic_error
{
public:
	/// Construct the exception.
	explicit precondition_violated(
		/// Message contained in the exception.
		std::string const& message)
		: logic_error(message)
	{ }
};

/******************************************************************************/
/*                                                                            */
/* postcondition_violated                                                     */
/*                                                                            */
/******************************************************************************/

/// Exception class for postcondition violations.
//!
//! In SGL, a postcondition is a condition or predicate that must always be true 
//! after the execution of some section of code. 
//! 
//! SGL checks postconditions with the SGL_POSTCONDITION macro, which - when 
//! defined - throws the postcondition_violated exception when the postcondition 
//! is not true.
//!
//! The user of SGL can inhibit this behavior by defining the 
//! SGL_POSTCONDITION(condition, message) macro as an empty macro before the 
//! inclusion of any SGL header file. 
class postcondition_violated : public std::logic_error
{
public:
	/// Construct the exception.
	explicit postcondition_violated(
		/// Message contained in the exception.
		std::string const& message)
		: logic_error(message)
	{ }
};

/******************************************************************************/
/*                                                                            */
/* invariant_violated                                                         */
/*                                                                            */
/******************************************************************************/

/// Exception class for invariant violations.
//!
//! In SGL, an invariant is a predicate that is supposed to remain true 
//! throughout the whole lifetime of a class.
//! 
//! SGL checks invariants with the SGL_INVARIANT macro, which - when defined -
//! throws the invariant_violated exception when the invariant is not true.
//!
//! The user of SGL can inhibit this behavior by defining the 
//! SGL_INVARIANT(condition, message) macro as an empty macro before the 
//! inclusion of any SGL header file. 
class invariant_violated : public std::logic_error
{
public:
	/// Construct the exception.
	explicit invariant_violated(
		/// Message contained in the exception.
		std::string const& message)
		: logic_error(message)
	{ }
};


} // namespace sgl

#endif // __sgl_exceptions_h__
